package 代码记录.校招笔试真题.笔试真题_2023.水滴;

/**
 * @author zx
 * @create 2023-03-23 21:22
 * 100%
 */
public class Test2 {
    public static boolean canDefeatAllMonsters (int initialAttack, int[] monsterHealths, int[] monsterPowers) {
        while(!isOk(monsterHealths)){
            int temp = Integer.MAX_VALUE;
            for(int i = 0;i < monsterHealths.length;i++){
                if(monsterHealths[i] - initialAttack >= 0){
                    monsterHealths[i] = monsterHealths[i] - initialAttack;
                }else{
                    monsterHealths[i] = 0;
                }
                if(monsterHealths[i] != 0){
                    temp = Math.min(temp,monsterPowers[i]);
                }
            }
            initialAttack -= temp;
            if(isOk(monsterHealths)){
                return true;
            }
            if(initialAttack <= 0){
                return false;
            }
        }
        return true;
    }

    /**
     * @return 判断怪物是否被杀死
     */
    private static boolean isOk(int[] monsterHealths){
        for(int i = 0;i < monsterHealths.length;i++){
            if(monsterHealths[i] != 0){
                return false;
            }
        }
        return true;
    }
}
